<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:56
 */
namespace app\admin\controller;

use app\admin\model\AnnouncementModel;

class Announcement extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->announcement = new AnnouncementModel();
    }
    public function index()
    {
        $list = $this->announcement->index();
        $page = $list->render();
        $count = count($list);
        $this->assign('list',$list);
        $this->assign('page',$page);
        $this->assign('count',$count);
        return view('announcement/index');
    }
    public function add()
    {
        if(request()->isAjax())
        {
            $res = $this->announcement->add();
            if($res)
            {
                return ['code'=>'1','message'=>'添加成功'];
            }else{
                return ['code'=>'0','message'=>'添加失败'];
            }
        }
        return view('announcement/add');
    }
    public function edit()
    {
        if(request()->isAjax())
        {
            $res = $this->announcement->edit();
            if($res)
            {
                return ['code'=>'1','message'=>'修改成功'];
            }else{
                return ['code'=>'0','message'=>'修改失败'];
            }
        }
        $id = input('id');
        $res = $this->announcement->getOneId($id);
        $this->assign('data',$res);
        return view('announcement/edit');
    }
    public function del()
    {
        $res = $this->announcement->del();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
    public function dell()
    {
        $res = $this->announcement->dell();
        if($res)
        {
            return ['code'=>'1','message'=>'删除成功'];
        }else{
            return ['code'=>'0','message'=>'删除失败'];
        }
    }
}